package ar.com.ctrln.view.sistema.login.component;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Tabbox;
import org.zkoss.zul.Tabpanel;
import org.zkoss.zul.Toolbarbutton;

public class LoginController extends SelectorComposer<Component> {

	/**
	 * 
	 */

	@Wire("#tabbox")
	Tabbox tabbox;

	@Wire("#principalTab")
	Tabpanel principalTab;
	
	@Wire
	Toolbarbutton reporte;
	
	Tabpanel panel;

	private static final long serialVersionUID = -1621438830264602032L;

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		// TODO Auto-generated method stub
		super.doAfterCompose(comp);
	}
	
	@Listen("onCreate = #principalTab")
	public void createPrincipalTab(){
		Executions.createComponents("/zul/principal/principal.zul", principalTab, null);
	}
	
	@Listen("onCreate = #principalTab")
	public void gotoPrincipal(){
		
	}
	
	@Listen("onClick = #reporte")
	public void gotoReportes(){
		String url = "http://192.168.236.129/ReportPortal/login.aspx";
		 Executions.getCurrent().sendRedirect(url, "_blank");
	}

	@Listen("onSelect = #tabbox")
	public void load() {
	
		panel = tabbox.getSelectedPanel();
		if (panel != null && panel.getChildren().isEmpty()) {
			if (panel.getId() == "principalTab") {
				
			}
			if (panel.getId().equals("calendarioTab")) {
				Executions.createComponents("/zul/calendar/calendario.zul",
						panel, null);
			}
			if (panel.getId().equals("administracionTab")) {
				Executions.createComponents(
						"/zul/administracion/administracion.zul", panel, null);
			}
			if (panel.getId().equals("ventasTab")) {
				Executions.createComponents("/zul/ventas/ventas.zul", panel,
						null);
			}
			if (panel.getId().equals("comprasTab")) {
				Executions.createComponents("/zul/compras/compras.zul", panel,
						null);
			}
			if (panel.getId().equals("mantenimientoTab")) {
				Executions.createComponents(
						"/zul/mantenimiento/mantenimiento.zul", panel, null);
			}
			if (panel.getId().equals("reportesTab")) {
				Executions.createComponents("/zul/reportes/reportes.zul",
						panel, null);
			}
		}
	}

}
